using System;
using System.Collections;
using System.Globalization;
using UnityEngine;
using TMPro;

public class WaveForm : MonoBehaviour
{
    public TMP_Text countDownText;
    public TMP_Text waveNumberText;
    public CanvasGroup canvasGroup;
    public GameObject goods;
    public GameObject goods1;
    public GameObject goods2;
    public GameObject goods3;
    bool isCountingDown;
    float countDownTime;
    bool isShowGoods;

    private void Awake()
    {
        ResourceManager.instance.PlayGameMusic();//设定播放的片段
        countDownText.alpha = 1;
        canvasGroup.alpha = 1;
        countDownTime = WaveManager.timeBetweenWaves;

    }
    private void Update()
    {
        //关卡数
        waveNumberText.SetText(WaveManager.levelNumber.ToString());
        isCountingDown = WaveManager.isCountingDown;
        countDownText.gameObject.SetActive(isCountingDown);
        //倒计时
        if (!isCountingDown)
        {
            //隐藏商店
            goods1.SetActive(false);
            goods2.SetActive(false);
            goods3.SetActive(false);
            isShowGoods = true;
            countDownTime = WaveManager.timeBetweenWaves;
            return;
        }
        else
        {
            if (isShowGoods && WaveManager.levelNumber!=1)
            {
                //显示商店
                goods1.SetActive(true);
                goods2.SetActive(true);
                goods3.SetActive(true);
                isShowGoods = false;
            }
        }

        countDownTime -= Time.deltaTime;

        if (countDownTime % 1 > 0.5f)
        {
            countDownText.alpha -= Time.deltaTime * 2;
        }
        else
        {
            countDownText.alpha += Time.deltaTime * 2;
        }
        if (countDownTime < 0.1f)
        {
            isCountingDown = false;
            canvasGroup.alpha = 0;
            countDownText.alpha = 0;
        }
        else
        {
            canvasGroup.alpha = 1;
            countDownText.alpha = 1;
            countDownText.SetText(Mathf.Round(countDownTime).ToString(CultureInfo.InvariantCulture));
        }
    }
}
